home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9209.ARJ / 1009040A < prev    next >
Text File  |  1992-04-03  |  8KB  |  245 lines

  1. /***                   LISTING 1                ***/
  2. /***                                            ***/
  3. /***                    serial.h                ***/
  4.  
  5. #include <dos.h>
  6.  
  7. #define COM1      0
  8. #define COM2      1
  9. #define COM3      2
  10. #define COM4      3
  11.  
  12. #define COM1BASE  0x3F8  /* Base address for COM1 */
  13. #define COM2BASE  0x2F8  /* Base address for COM2 */
  14. #define COM3BASE  0x3E8  /* Base address for COM3 */
  15. #define COM4BASE  0X2E8  /* Base address for COM4 */
  16.  
  17. /*** ****************************************** ***/
  18. /***    8250 UART user accessible registers     ***/
  19. /***    offsets relative to COMBASE address.    ***/
  20. /*** ****************************************** ***/
  21.  
  22. #define TXR    0     /* Transmit register (WRITE) */
  23. #define RXR    0     /* Receive register  (READ)  */
  24. #define IER    1     /* Interrupt Enable          */
  25. #define IIR    2     /* Interrupt ID              */
  26. #define LCR    3     /* Line control              */
  27. #define MCR    4     /* Modem control             */
  28. #define LSR    5     /* Line Status               */
  29. #define MSR    6     /* Modem Status              */
  30. #define SRP    7     /* Scratch Pad               */
  31. #define DLL    0     /* Divisor Latch Low         */
  32. #define DLH    1     /* Divisor latch High        */
  33.  
  34. /*** ****************************************** ***/
  35. /***    INTERRUPT ENABLE REGISTER (OFFSET 1)    ***/
  36. /*** ****************************************** **
  37.  
  38.  Bit values of the Interrupt Enable Register (IER).
  39.  
  40.   bit            meaning
  41.   ---            -------
  42.    0             Interrupt when byte is recieved.
  43.    1             Interrupt when transmitter hold-
  44.          ing register is empty.
  45.    2             Interrupt when there is an error
  46.          in data reception.
  47.    3             Interrupt when any RS-232 inputs
  48.          change states.
  49.    4-7           Not used. (Always 0)
  50.                           */
  51. #define RX_INT          0x01
  52. #define TBE_INT         0x02
  53. #define ERR_INT         0x03
  54. #define RS_INT          0x04
  55.  
  56. /*** ***************************************** ***/
  57. /*  INTERRUPT IDENTIFICATION REGISTER (OFFSET 2) */
  58. /*** ***************************************** **
  59.  
  60.  Bit values of the Interrupt Identification (IIR).
  61.  
  62.   bit            meaning
  63.   ---            -------
  64.    0             0 = Interrupt pending. 
  65.    1-2           Interrupt ID code
  66.            00 = RS-232 input
  67.            01 = Transmitter buffer empty
  68.            10 = Data received (RX_ID)
  69.            11 = Reception error, or BREAK.
  70.    3-7            Not used.                     */
  71.          
  72. #define RX_ID           0x04
  73. #define RX_MASK         0x07
  74.  
  75. /*** ***************************************** ***/
  76. /***     LINE CONTROL REGISTER (OFFSET 3)      ***/
  77. /*** ***************************************** **
  78.  
  79.  Bit values of the Line Control Register (LCR).
  80.  
  81.   bit            meaning
  82.   ---            -------
  83.   0-1            00 = 5 bits 
  84.          01 = 6 bits 
  85.          10 = 7 bits 
  86.          11 = 8 bits.
  87.   2              Stop bits.
  88.   3              0 = parity off
  89.          1 = parity on.
  90.   4              0 = parity odd
  91.          1 = parity even.
  92.   5              Sticky parity.
  93.   6              Set break.
  94.   7              Toggle port addresses. (DLAB)    */
  95.  
  96. #define NO_PARITY       0x00
  97. #define EVEN_PARITY     0x18
  98. #define ODD_PARITY      0x08
  99. #define DLAB            0x80
  100.  
  101. /*** ***************************************** ***/
  102. /***     MODEM CONTROL REGISTER (OFFSET 4)     ***/
  103. /*** ***************************************** **
  104.  
  105.  Bit values of the Modem Control Register (MCR).
  106.  
  107.   bit            meaning
  108.   ---            -------
  109.    0             1 assert DTR (Data Terminal Ready)
  110.    1             1 assert RTS (Request to Send)
  111.    2             User definable output.      (GPO1)
  112.    3             Enable Interrupts on 8250.  (GPO2)
  113.    4             Local Loopback Test.
  114.    5-7           Not used. (Always 0)
  115.                          */
  116. #define DTR             0x01
  117. #define RTS             0x02
  118. #define GPO1            0x04
  119. #define GPO2            0x08
  120. #define EN_INT          0x08
  121.  
  122. /*** ***************************************** ***/
  123. /***      LINE STATUS REGISTER (OFFSET 5)      ***/
  124. /*** ***************************************** **
  125.  
  126.  Bit values held in the Line Status Register (LSR).
  127.  
  128.   bit            meaning
  129.   ---            -------
  130.    0             Data ready.
  131.    1             Overrun error.
  132.    2             Parity error.
  133.    3             Framing error.
  134.    4             Break detect.
  135.    5             Transmitter buffer empty.
  136.    6             Transmitter empty.
  137.    7             Time out.                       */
  138.  
  139. #define RCVRDY          0x01
  140. #define OVRERR          0x02
  141. #define PRTYERR         0x04
  142. #define FRMERR          0x08
  143. #define BRKERR          0x10
  144. #define XMTRDY          0x20
  145. #define XMTRSR          0x40
  146. #define TIMEOUT         0x80
  147.  
  148. /*** ***************************************** ***/
  149. /***     MODEM STATUS REGISTER (OFFSET 6)      ***/
  150. /*** ***************************************** **
  151.  
  152.  Bit values held in the Modem Status Register (MSR).
  153.  
  154.   bit            meaning
  155.   ---            -------
  156.    0               Delta CTS.
  157.    1               Delta DSR.
  158.    2               Delta RI.
  159.    3               Delta DCD.
  160.    4               CTS (Clear to Send).
  161.    5               DSR (Data Set Ready).
  162.    6               RI (Ring indicator).
  163.    7               DCD (Data Carrier Detected).  */
  164.  
  165. #define D_CTS           0x01
  166. #define D_DSR           0x02
  167. #define D_RI            0x04
  168. #define D_DCD           0x08
  169. #define CTS             0x10
  170. #define DSR             0x20
  171. #define RI              0x40
  172. #define DCD             0x80
  173.  
  174. /*** ***************************************** ***/
  175. /***     SCRATCH PAD REGISTER (OFFSET 7)       ***/
  176. /*** ***************************************** **
  177.  
  178.   This register has no function and may be use  
  179.   as any other byte of RAM, but note that this 
  180.   register does not exist on early versions of
  181.   the 8250.
  182.                          */
  183. /*** ***************************************** ***/
  184. /***     LSB & MSB BAUD RATE DIVISOR LATCH     ***/
  185. /***             (REGISTER  8 & 9)             ***/
  186. /*** ***************************************** **
  187.  
  188.   These two register are use to generate the
  189.   baud rates.  They are reached by setting the
  190.   DLAB bit of the LINE CONTROL REGISTER to a one
  191.   and addressing Register 8 as an OFFSET of 0 
  192.   and Register 9 as an OFFSET of 1.              */
  193.  
  194. /*** ***************************************** ***/
  195. /*** These are the port addresses of the 8259  ***/
  196. /*** Programmable Interrupt Controller (PIC).  ***/
  197. /*** ***************************************** ***/
  198.  
  199. #define IMR  0x21 /* Interrupt Mask Register Port*/
  200. #define ICR  0x20 /* Interrupt Control Port      */
  201.  
  202. /***  An end of interrupt needs to be sent to  ***/
  203. /***  the Control Port of the 8259 when a      ***/ 
  204. /***  hardware interrupt ends.                 ***/
  205.  
  206. #define EOI  0x20            /* End Of Interrupt */
  207.  
  208. /*** The (IMR) tells the (PIC) to service an   ***/
  209. /*** interrupt only if it is not masked (FALSE).**/
  210.  
  211. /*** ***************************************** ***/
  212. /***    INTERRUPT ADDRESS FOR COM PORTS        ***/
  213. /*** ***************************************** ***/
  214.  
  215. #define IRQ4  0xEF            /*** COM1 & COM3 ***/
  216. #define IRQ3  0xF7            /*** COM2 & COM4 ***/
  217.  
  218. /*** ***************************************** ***/
  219. /***        GENERAL DEFINE STATEMENTS          ***/
  220. /*** ***************************************** ***/
  221.  
  222. #define SBUFSIZ  4000
  223.  
  224. /*** ***************************************** ***/
  225. /***               PROTOTYPES                  ***/
  226. /*** ***************************************** ***/
  227.  
  228. int SerialOut(char Char_Value);
  229. int SerialIn(void);
  230. void interrupt far ReceiveData(void);
  231. int IntSerialIn(void);
  232. int SetPort (int ComPort);
  233. int SetBaud(long Baud);
  234. int SetOthers(int Parity, int DataBits, int StopBits);
  235. int SetSerial(int ComPort, long Baud, int Parity,
  236.               int DataBits, int StopBits);
  237. void Setvects(int ComPort);
  238. void Resvects(int ComPort);
  239. void EnableInt(int ComPort);
  240. void DisableInt(void);
  241. void InitSerial(int ComPort);
  242. void CloseSerial(int ComPort);
  243. void Assert(int request);
  244. void Assert_Off(int request);
  245. int Status(int request);